<template>
    <!-- 入场管理-入场申请 -->
    <div class="empReward">
        <div class="top">
            <div class="search">
                <div class="list">
                    <!-- <DatePicker type="daterange" :clearable="false" placeholder="开始时间   -   结束时间" style="width: 200px"
                        v-model="value" @on-change="getTime"></DatePicker> -->
                    <el-date-picker
                        v-model="value"
                        type="datetimerange"
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        @change="getTime"
                        :clearable="false"
                        format="yyyy-MM-dd HH:mm:ss"
                        value-format="yyyy-MM-dd HH:mm:ss">
                    </el-date-picker>
                </div>
                <!-- <div class="list">
                    <Input placeholder="搜索申请人" style="width:150px" v-model="keyword" clearable />
                    <input type="password" autocomplete="new-password" style="display: none" />
                </div> -->
                <input type="text" class="intBox" style="display:none" />
                <div class="list" @click="onSerch">
                    <Button type="primary">搜索</Button>
                </div>
                <div class="list" @click="onReset">
                    <Button>重置</Button>
                </div>
            </div>
            <div class="down">
                <el-button type="primary" @click="updateRow(0)" size="small" plain>添加入场申请</el-button>
            </div>
        </div>
        <div class="bottom">
            <div class="table">
                <el-table :data="list" :height="tableHeight" :stripe="true" style="width: 100%">
                    <el-table-column prop="id" label="ID" width="55"></el-table-column>
                    <el-table-column prop="name" label="姓名" width="100"></el-table-column>
                    <!-- <el-table-column prop="idCard" label="身份证号" min-width="140"></el-table-column> -->
                    <el-table-column prop="entryPersonNames" label="入场人员">
                        <template slot-scope="scope">
                            <el-link :underline="false" v-for="(item,index) in scope.row.entryPersonNames" :key="index">
                                {{item + ', '}}
                            </el-link>
                        </template>
                    </el-table-column>
                    <el-table-column prop="entryTime" label="入场时间" width="110"></el-table-column>
                    <el-table-column prop="leaveTime" label="离场时间" width="110"></el-table-column>
                    <el-table-column prop="unit" label="所属单位" min-width="180"></el-table-column>
                    <el-table-column prop="uploadedFile" label="附件文件" min-width="100">
                        <template slot-scope="scope">
                            <el-link v-if="scope.row.uploadedFile" target="_blank" :href="scope.row.uploadedFile" type="primary" >附件</el-link>
                            <el-link v-else type="info" :underline="false" >附件</el-link>
                        </template>
                    </el-table-column>
                    <el-table-column prop="reason" label="事由" min-width="200"></el-table-column>
                    <el-table-column prop="applyTime" label="申请时间" width="110"></el-table-column>

                    <el-table-column label="操作" align="center" fixed="right" min-width="120">
                        <template slot-scope="scope">
                            <!-- <el-button type="text" size="small">待审核</el-button> -->
                            <el-button type="text" size="small" @click="onEdit(scope.row)">编辑</el-button>
                            <!-- <el-button type="text" size="small">提交审核</el-button> -->
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <div class="clearfix"  >
                <div class="float-right">
                    <Page v-if="totalCount" style="margin: 20px 0;text-align: center;" :current.sync="current"
                        :total="totalCount" :page-size="pageSize" show-elevator show-total show-sizer
                        @on-change="pageChange" @on-page-size-change="pageSizeChange">
                    </Page>
                </div>
            </div>
        </div>

        <Modal v-model="deleteModal" title="删除" width="360px;" :mask-closable="false">
            <div style="margin:10px">确定要删除这条数据吗？</div>
            <div slot="footer">
                <el-button @click="cancel(2)" type="info" size="small" plain>取消</el-button>
                <el-button @click="detele" type="primary" size="small" plain v-preventReClick="1500">确定</el-button>
            </div>
        </Modal>

        <Modal v-model="updateModal" :title="popupType == 1 ? '添加入场申请' : '修改入场申请'" width="70%" min-width="520px" :mask-closable="false">
            <div class="item">
                <span class="tip">*</span>
                <span>标题:</span>
                <Input v-model="entryTitle" type="text" placeholder="请输入标题" style="width: 300px" show-word-limit />
            </div>
            <div class="item">
                <span class="tip">*</span>
                <span>入场人员:</span>
                <el-select v-model="entryPersonIds" multiple filterable style="width:300px" placeholder="请选择入场人员">
                    <el-option v-for="item in QueryPersonnelList" :key="item.emp_id" :label="item.name" :value="item.emp_id"></el-option>
                </el-select>
                <!-- <div style="width: 300px; height: 100%; border: 1px solid #DCDFE6; border-radius: 4px; padding: 5px 10px;"
                    :style="entryPersonIdName == '' ? 'color: #b2b2b2;' : ''" @click="EntrantsDialog()">
                    {{entryPersonIdName || '请选择入场人员'}}
                </div> -->
            </div>
            <div class="item">
                <span class="tip">*</span>
                <span>选择班组长:</span>
                <Select v-model="bzzValue" style="width:300px" placeholder="请选择选择班组长" :filterable="true"
                    @on-change="getEmpType">
                    <Option v-for="item in UserList" :value="item.empId" :key="item.empId">{{ item.empName }}</Option>
                </Select>
            </div>
            <div class="item">
                <span class="tip">*</span>
                <span>入场时间:</span>
                <!-- <DatePicker type="date" v-model="AdmissionTime" placeholder="请选择入场时间" style="width: 300px" @on-change="getDate"></DatePicker> -->
                <el-date-picker v-model="AdmissionTime" type="datetime" placeholder="请选择入场时间" style="width: 300px"
                    format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss" >
                </el-date-picker>
            </div>
            <div class="item">
                <span class="tip">*</span>
                <span>离场时间:</span>
                <!-- <DatePicker type="date" v-model="DepartureTime" placeholder="请选择离场时间" style="width: 300px" @on-change="getDate2"></DatePicker> -->
                <el-date-picker v-model="DepartureTime" type="datetime" placeholder="请选择入场时间" style="width: 300px"
                    format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss" >
                </el-date-picker>
            </div>
            <div class="item">
                <span class="tip">*</span>
                <span>分包单位:</span>
                <Select v-model="fbdwValue" style="width:300px" placeholder="请选择分包单位" :filterable="true"
                    @on-change="getEmpType">
                    <Option v-for="item in Institution_fbdw" :value="item.id" :key="item.id">{{ item.name }}</Option>
                </Select>
            </div>
            <div class="item">
                <span class="tip">*</span>
                <span>总包单位:</span>
                <Select v-model="zbdwValue" style="width:300px" placeholder="请选择总包单位" :filterable="true"
                    @on-change="getEmpType">
                    <Option v-for="item in Institution_zbdw" :value="item.id" :key="item.id">{{ item.name }}</Option>
                </Select>
            </div>
            <div class="item">
                <span class="tip">*</span>
                <span>监理单位:</span>
                <Select v-model="jldwValue" style="width:300px" placeholder="请选择监理单位" :filterable="true"
                    @on-change="getEmpType">
                    <Option v-for="item in Institution_jldw" :value="item.id" :key="item.id">{{ item.name }}</Option>
                </Select>
            </div>
            <div class="item">
                <span class="tip">*</span>
                <span>业主单位:</span>
                <Select v-model="yzdwValue" style="width:300px" placeholder="请选择业主单位" :filterable="true"
                    @on-change="getEmpType">
                    <Option v-for="item in Institution_yzdw" :value="item.id" :key="item.id">{{ item.name }}</Option>
                </Select>
            </div>
            <div class="item">
                <span class="tip">*</span>
                <span>上传图片:</span>
                <el-upload style="width:300px" class="upload-demo" :on-preview="handlePreview" :on-remove="handleRemove" action=""
                    :before-remove="beforeRemove" multiple :limit="1" :on-exceed="handleExceed" :file-list="fileList"
                    :http-request="httpRequest">
                    <el-button size="small" type="primary">点击上传</el-button>
                    <div slot="tip" class="el-upload__tip"><!-- 上传文件不超过500kb --></div>
                </el-upload>
            </div>
            <div class="item">
                <span class="tip">*</span>
                <span>事由:</span>
                <Input v-model="checkDesc" type="textarea" placeholder="请输入事由内容" :maxlength="200" style="width: 300px" show-word-limit />
            </div>
            <div class="item"></div>
            <div slot="footer">
                <el-button @click="cancel(1)" type="info" size="small" plain>取消</el-button>
                <el-button @click="submitAll" type="primary" size="small" plain v-preventReClick="1500" :loading="ModalLoading">确定</el-button>
            </div>
        </Modal>

        <el-dialog title="入场人员" :visible.sync="dialogVisible" width="800px" :before-close="handleClose">
            <div class="EmpDiv">
                <div class="EmpLeft">
                    <el-tree :data="GroupByDeptIdList" :props="defaultProps" @node-click="handleNodeClick"></el-tree>
                </div>
                <div class="EmpRight">
                    <el-table ref="multipleTable" :data="EmptableData" tooltip-effect="dark" height="50vh"
                        style="width: 100%" @selection-change="handleSelectionChange" :row-key="row => row.empId">
                        <el-table-column type="selection" width="50" align="center" reserve-selection></el-table-column>
                        <!-- <el-table-column prop="empId" label="ID" align="center"></el-table-column> -->
                        <el-table-column prop="empName" label="用户头像" align="center">
                            <template slot-scope="scope">
                                <el-image
                                    :src="scope.row.avatar ? scope.row.avatar : require('@/assets/images/emp/gate/nopeople.png')"
                                    style="display:block; width:40px; height:40px; border-radius:50%; margin: 0 auto;"
                                    :preview-src-list="[scope.row.avatar ? scope.row.avatar : require('@/assets/images/emp/gate/nopeople.png')]">
                                </el-image>
                            </template>
                        </el-table-column>
                        <el-table-column prop="empName" label="姓名" align="center"></el-table-column>
                        <el-table-column prop="gender" label="性别" align="center">
                            <template slot-scope="scope">
                                <span v-if="scope.row.gender == 1" >男</span>
                                <span v-if="scope.row.gender == 2" >女</span>
                            </template>
                        </el-table-column>
                    </el-table>
                </div>
            </div>

            <span slot="footer" class="dialog-footer">
                <el-button @click="handleClose">取 消</el-button>
                <el-button type="primary" @click="confirmSelection">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
    import { uniq } from "shelljs";
    import {
        getEmpRewardList,
        getEmpRewardAdd,
        getEmpRewardDel,
        getAllPersonnelList,
        getSelectValue
    } from "@/api/api.js";
    import {
        apiApplyList,
        apiApplyWorkPersonnel,
        apiApplyWorkQueryPersonnel,
        getUserList,
        apiApplyWorkQueryInstitution,
        apiApplyEdit,
        apiApplyWorkQueryEntryInfo,
        appDocumentManageFileUpload,
        apiEmpLeaderList,
        getGroupListByDeptId,
        getApiEmpList
    } from "@/api/apifox.js";
    export default {
        data() {
            return {
                fileList: [],
                current: 1,
                pageSize: 10,
                pageNum: 1,
                totalCount: "",
                corpType: "",
                projectId: "",
                keyword: "",
                list: [],
                corpList: [],
                updateModal: false,
                isAdd: true,
                removeId: "",
                deleteModal: false,
                btnList: [],
                deptName: "",
                startDate: "",
                endDate: "",
                value: [],
                empList: [],
                empId: "",
                empName: "",
                date: "",
                tableHeight: window.innerHeight - 355,
                itemList: [], //改动 下拉值
                itemId: "",
                radio: "",
                description: "",
                labelByValue: {},

                QueryPersonnelList: [], // 入场人员列表
                queryInstitutionList: [], // 机构列表
                Institution_yzdw: [], // 业主单位
                Institution_jldw: [], // 监理单位
                Institution_zbdw: [], // 总包单位
                Institution_fbdw: [], // 分包单位
                UserList: [], // 班组长列表

                entryTitle: '', // 入场标题
                entryPersonIds: [], // 入场人员
                entryPersonIdName: '', // 入场人员名称
                bzzValue: '', // 班组长
                AdmissionTime: '', // 入场时间
                DepartureTime: '', // 离场时间
                fbdwValue: '', // 分包单位
                zbdwValue: '', // 总包单位
                jldwValue: '', // 监理单位
                yzdwValue: '', // 业主单位
                checkDesc: '', // 申请事由
                fileImg: '', // 申请图片

                popupType: 1, // 1添加，2修改
                dataData: '', //

                ModalLoading: false, // 弹窗按钮加载状态

                GroupByDeptIdList: [], // 公司/班组列表
                defaultProps: {
                    children: 'children',
                    label: 'label'
                },

                dialogVisible: false, // 对话框弹出层
                EmpSize: 9999,
                EmpNum: 1,
                corpId: null,
                groupId: null,
                EmptableData: [],
                multipleSelection: [],
            };
        },
        computed: {
            porjectObject() {
                return this.$store.state.porjectObject;
            }
        },
        watch: {
            porjectObject(val, oldVal) {
                if (val.deptId != oldVal.deptId) {
                    this.projectId = val.deptId;
                    this.deptName = val.name;
                    this.pageNum = 1;
                    this.current = 1;
                    this.keyword = "";
                    this.value = [];
                    this.getAllList();
                    this.getEmpList();
                }
            }
        },

        created() {
            this.selectValue(); //改动 初次加载下拉数据
        },
        mounted() {
            this.projectId = this.$store.state.porjectObject.deptId;
            this.deptName = this.$store.state.porjectObject.name;
            this.getAllList();
            this.getEmpList();
            this.btnList = JSON.parse(localStorage.getItem("arr"));
        },
        methods: {
            /* 实现图片上传功能 -开始 */
            httpRequest(item) {
                console.log('0', item.file.name);
                var formData = new FormData()
                formData.append('file', item.file)
                appDocumentManageFileUpload(formData).then(res => {
                    console.log('上传结果', res);
                    this.$Message.success(res.data.name + '上传成功');

                    this.fileImg = res.data.path // 附件路径

                }).catch(() => { })
            },
            handleRemove(file, fileList) {
                console.log('1', file, fileList);
                this.fileImg = '' // 附件路径
            },
            handlePreview(file) {
                console.log('2', file);
            },
            handleExceed(files, fileList) {
                console.log('3', files, fileList);
                this.$message.warning(`当前限制选择 1 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
            },
            beforeRemove(file, fileList) {
                console.log('4', file, fileList);
                return this.$confirm(`确定移除 ${file.name}？`);
            },
            /* 实现图片上传功能 - 结束 */

            EntrantsDialog() {
                this.multipleSelection = [];

                getGroupListByDeptId({
                    deptId: this.projectId
                }).then(res => {
                    if (res.code == 200) {
                        let originalData = res.data.list
                        this.GroupByDeptIdList = originalData.map(corp => ({
                            label: corp.corpName,
                            DeptId: corp.corpId,
                            type: 'corp',
                            children: corp.groupList.map(group => ({
                                label: group.groupName,
                                DeptId: group.groupId,
                                type: 'group',
                                // 如果有三级数据可在此处继续添加children，当前数据中无三级结构
                                children: []
                            }))
                        }));
                        console.log('GroupByDeptIdList: ', this.GroupByDeptIdList);

                        this.dialogVisible = true;
                    } else {
                        this.$Message.warning(res.msg);
                    }
                }).catch(error => {
                    console.log(error);
                });

                this.EmptableData = [];
                this.corpId = ''
                this.groupId = ''
                this.onApiEmpList();
            },

            onApiEmpList() {
                getApiEmpList({
                    deptId: this.projectId,
                    pageSize: this.EmpSize,
                    pageNum: this.EmpNum,
                    postState: 1,

                    corpId: this.corpId,
                    groupId: this.groupId,
                }).then(res => {
                    if (res.code == 200) {
                        console.log(res);
                        this.EmptableData = res.data.list
                    } else {
                        this.$Message.warning(res.msg);
                    }
                }).catch(error => {
                    console.log(error);
                });
            },

            handleNodeClick(data) {
                console.log('handleNodeClick: ', data);
                console.log('this.multipleSelection: ', this.multipleSelection)

                if(data.type == 'corp') {
                    this.corpId = data.DeptId
                    this.groupId = ''
                } else if (data.type == 'group') {
                    this.groupId = data.DeptId
                    this.corpId = ''
                } else {
                    this.groupId = ''
                    this.corpId = ''
                }
                this.EmptableData = [];
                this.onApiEmpList();
            },
            handleSelectionChange(val) {
                if(val) {
                    this.multipleSelection = val.map(e => ({
                        empId: e.empId,
                        empName: e.empName,
                    }));
                }
                console.log('this.multipleSelection: ', this.multipleSelection)
            },

            //获取所有人员
            getEmpList() {
                let params = {
                    deptId: this.projectId
                };



                getAllPersonnelList(params).then(res => {
                    if (res.code == 200) {
                        this.empList = res.data.list;
                    } else {
                        this.$Message.warning(res.msg);
                    }
                }).catch(error => {
                    console.log(error);
                });

                /* 入场人员列表 */
                apiApplyWorkQueryPersonnel({
                    deptId: this.projectId,
                    empNames: [],
                    leaderFlag: 0,
                }).then(res => {
                    if (res.code == 200) {
                        this.QueryPersonnelList = res.data;
                    } else {
                        this.$Message.warning(res.msg);
                    }
                }).catch(error => {
                    console.log(error);
                });

                /* 班组长列表 */
                /* apiApplyWorkQueryPersonnel({
                    deptId: this.projectId,
                    empNames: [],
                    leaderFlag: 1,
                }).then(res => {
                    if (res.code == 200) {
                        this.UserList = res.data;
                    } else {
                        this.$Message.warning(res.msg);
                    }
                }).catch(error => {
                    console.log(error);
                }); */
                apiEmpLeaderList({
                    deptId: this.projectId,
                }).then(res => {
                    if (res.code == 200) {
                        this.UserList = res.data;
                    } else {
                        this.$Message.warning(res.msg);
                    }
                }).catch(error => {
                    console.log(error);
                });

                apiApplyWorkQueryInstitution(params).then(res => {
                    if (res.code == 200) {
                        this.queryInstitutionList = res.data
                        // 业主单位
                        this.Institution_yzdw = this.queryInstitutionList.filter(item => item.companyType == 1);
                        // 监理单位
                        this.Institution_jldw = this.queryInstitutionList.filter(item => item.companyType == 2);
                        // 总包单位
                        this.Institution_zbdw = this.queryInstitutionList.filter(item => item.companyType == 3);
                        // 分包单位
                        this.Institution_fbdw = this.queryInstitutionList.filter(item => item.companyType == 4);
                    } else {
                        this.$Message.warning(res.msg);
                    }
                }).catch(error => {
                    console.log(error);
                });
            },
            getAllList() {
                let params = {
                    pageSize: this.pageSize, // 分页大小
                    pageNum: this.pageNum, // 分页页码
                    keyword: this.keyword,
                    deptId: this.projectId,
                    // startTiem: this.startDate, // 开始时间
                    // endTiem: this.endDate, // 结束时间
                    // createUserId: [], // 创建人Id
                    // isExit: null, // 是否离场 1到场 2离场
                    // id: null,
                    // pidList: [],
                    entryTimeBegin: this.startDate, // 开始时间
                    entryTimeEnd: this.endDate, // 结束时间
                };
                apiApplyList(params).then(res => {
                    console.log('apiApplyList 请求结果', res)
                    if (res.code == 200) {
                        this.list = res.data.list;
                        this.totalCount = res.data.total;
                    } else {
                        this.$Message.warning(res.msg);
                    }
                }).catch(error => {
                    console.log(error);
                });
            },
            getTime(value) {
                /* this.startDate = value[0];
                this.endDate = value[1]; */
                if (value === null) {
                    console.log("点击了清空按钮，日期已清空");
                    this.startDate = '';
                    this.endDate = '';
                    // 处理清空后的逻辑
                } else {
                    console.log("选择了日期：", value);
                    this.startDate = value[0];
                    this.endDate = value[1];
                }

                // this.pageNum = 1;
                // this.current = 1;
                // this.getAllList();
            },
            // onSearch() {
            //     this.pageNum = 1;
            //     this.current = 1;
            //     this.getAllList();
            // },

            onSerch() {
                this.pageNum = 1;
                this.current = 1;
                this.getAllList();
            },
            onReset() {
                this.value = []
                this.startDate = null
                this.endDate = null
                this.keyword = null
                this.pageNum = 1;
                this.current = 1;
                this.getAllList();
                this.getEmpList();
            },
            pageChange(index) {
                this.pageNum = index;
                this.getAllList();
            },
            pageSizeChange(index) {
                this.pageSize = index;
                this.getAllList();
            },
            updateRow() {
                this.empId = "";
                this.empName = "";
                this.date = "";
                this.radio = 1;
                this.itemId = "";
                this.description = "";

                this.entryPersonIds = []; // 入场人员id
                this.entryPersonIdName = ''; // 入场人员名称

                this.multipleSelection = []; // 入场人员列表状态
                // this.$refs.multipleTable.clearSelection();

                this.bzzValue = ''; // 班组长id
                this.AdmissionTime = ''; // 入场时间
                this.DepartureTime = ''; // 离场时间
                this.fbdwValue = ''; // 分包单位id
                this.zbdwValue = ''; // 总包单位id
                this.jldwValue = ''; // 监理单位id
                this.yzdwValue = ''; // 业主单位id
                this.checkDesc = ''; // 申请事由
                this.entryTitle = ''; // 入场标题
                this.fileImg = ''; // 申请图片
                this.fileList = []; // 申请图片

                this.popupType = 1;

                this.updateModal = true;
            },
            onEdit(row) {
                this.entryPersonIds = []; // 入场人员id
                this.entryPersonIdName = ''; // 入场人员名称

                this.multipleSelection = []; // 入场人员列表状态
                // this.$refs.multipleTable.clearSelection();

                this.bzzValue = ''; // 班组长id
                this.AdmissionTime = ''; // 入场时间
                this.DepartureTime = ''; // 离场时间
                this.fbdwValue = ''; // 分包单位id
                this.zbdwValue = ''; // 总包单位id
                this.jldwValue = ''; // 监理单位id
                this.yzdwValue = ''; // 业主单位id
                this.checkDesc = ''; // 申请事由
                this.entryTitle = ''; // 入场标题
                this.fileImg = ''; // 申请图片
                this.fileList = []; // 申请图片
                this.dataData = '';

                console.log(row)
                this.popupType = 2;
                this.dataData = row;
                apiApplyWorkQueryEntryInfo({
                    id: row.id,
                }).then(res => {
                    console.log(res)
                    if (res.code == 200) {
                        this.entryPersonIds = res.data.entryPersonName; // 入场人员id
                        this.bzzValue = res.data.teamLeaderId; // 班组长id
                        this.AdmissionTime = res.data.entryTime; // 入场时间
                        this.DepartureTime = res.data.leaveTime; // 离场时间
                        this.fbdwValue = res.data.subcontractorId; // 分包单位id
                        this.zbdwValue = res.data.generalContractorId; // 总包单位id
                        this.jldwValue = res.data.supervisionUnitId; // 监理单位id
                        this.yzdwValue = res.data.ownerUnit; // 业主单位id
                        this.checkDesc = res.data.reason; // 申请事由
                        this.entryTitle = res.data.title; // 入场标题
                        this.fileImg = res.data.filePath; // 申请图片
                        if(this.fileImg) {
                            this.fileList.push({
                                url: this.fileImg,
                                name: '文件名称',
                            });
                        }
                        this.updateModal = true;
                    } else {
                        this.$Message.warning(res.msg);
                    }
                }).catch(error => {
                    console.log(error);
                });
            },
            getEmpType(index) {
                this.empId = index;
                this.empList.forEach(i => {
                    if (index == i.empId) {
                        this.empName = i.empName;
                    }
                });
            },
            getDate(value) {
                this.AdmissionTime = value;
            },
            getDate2(value) {
                this.DepartureTime = value;
            },
            handleClose(done) {
                this.dialogVisible = false;
            },
            confirmSelection() {

                this.entryPersonIdName = this.multipleSelection.map(item => item.empName).join(', ');
                this.entryPersonIds = this.multipleSelection.map(item => item.empId);

                this.dialogVisible = false;
            },

            submitAll() {
                console.log({
                    deptId: this.projectId.toString(), // 项目Id
                    entryPersonIds: this.entryPersonIds, // 入场人员id
                    teamLeaderId: this.bzzValue, // 班组长id
                    entryTime: this.AdmissionTime, // 入场时间
                    leaveTime: this.DepartureTime, // 离场时间
                    subcontractorId: this.fbdwValue, // 分包单位id
                    generalContractorId: this.zbdwValue, // 总包单位id
                    supervisionUnitId: this.jldwValue, // 监理单位id
                    ownerUnit: this.yzdwValue, // 业主单位id
                    reason: this.checkDesc, // 申请事由
                    title: this.entryTitle, // 入场标题
                    filePath: this.fileImg, // 申请图片
                    // entryCategoryName: this.entryPersonIdsObj.data[0].position, // 入场工种名称
                })
                // let params = {
                //     empId: this.empId,
                //     empName: this.empName,
                //     type: this.radio,
                //     item: this.itemId,
                //     description: this.description,
                //     date: this.date
                // };
                // this.fileImg =
                if(this.entryPersonIds == '') {
                    this.$Message.warning('请选择入场人员！');
                    return
                }
                if(this.bzzValue == '') {
                    this.$Message.warning('请选择班组长！');
                    return
                }
                if(this.AdmissionTime == '') {
                    this.$Message.warning('请选择入场时间！');
                    return
                }
                if(this.DepartureTime == '') {
                    this.$Message.warning('请选择离场时间！');
                    return
                }
                if(this.fbdwValue == '') {
                    this.$Message.warning('请选择分包单位！');
                    return
                }
                if(this.zbdwValue == '') {
                    this.$Message.warning('请选择总包单位！');
                    return
                }
                if(this.jldwValue == '') {
                    this.$Message.warning('请选择监理单位！');
                    return
                }
                if(this.yzdwValue == '') {
                    this.$Message.warning('请选择业主单位！');
                    return
                }
                if(this.checkDesc == '') {
                    this.$Message.warning('请输入申请事由！');
                    return
                }
                if(this.entryTitle == '') {
                    this.$Message.warning('请输入标题！');
                    return
                }
                if(this.fileImg == '') {
                    this.$Message.warning('请上传申请图片！');
                    return
                }

                this.ModalLoading = true;

                if(this.popupType == 1) {
                    let param = {
                    	deptId: this.projectId.toString(), // 项目Id
                    	entryPersonIds: this.entryPersonIds, // 入场人员id
                    	teamLeaderId: this.bzzValue, // 班组长id
                    	entryTime: this.AdmissionTime, // 入场时间
                    	leaveTime: this.DepartureTime, // 离场时间
                    	subcontractorId: this.fbdwValue, // 分包单位id
                    	generalContractorId: this.zbdwValue, // 总包单位id
                    	supervisionUnitId: this.jldwValue, // 监理单位id
                    	ownerUnit: this.yzdwValue, // 业主单位id
                    	reason: this.checkDesc, // 申请事由
                    	title: this.entryTitle, // 入场标题
                    	filePath: this.fileImg, // 申请图片
                    	// entryCategoryName: this.entryPersonIdsObj.data[0].position, // 入场工种名称
                    };
                    console.log('param: ', param);
                    // return
                    apiApplyWorkPersonnel(param).then(res => {
                        if (res.code == 200) {
                            this.$Message.success("操作成功");
                            this.updateModal = false;
                            this.getAllList();
                        } else {
                            this.$Message.warning(res.msg);
                        }

                        this.ModalLoading = false;
                    }).catch(error => {
                        console.log(error);
                        this.ModalLoading = false;
                    });
                } else {
                    let param = {
                        id: this.dataData.id,
                    	deptId: this.projectId.toString(), // 项目Id
                    	entryPersonIds: this.entryPersonIds, // 入场人员id
                    	teamLeaderId: this.bzzValue, // 班组长id
                    	entryTime: this.AdmissionTime, // 入场时间
                    	leaveTime: this.DepartureTime, // 离场时间
                    	subcontractorId: this.fbdwValue, // 分包单位id
                    	generalContractorId: this.zbdwValue, // 总包单位id
                    	supervisionUnitId: this.jldwValue, // 监理单位id
                    	ownerUnit: this.yzdwValue, // 业主单位id
                    	reason: this.checkDesc, // 申请事由
                        title: this.entryTitle, // 入场标题
                    	filePath: this.fileImg, // 申请图片
                    };
                    console.log('param: ', param);
                    apiApplyEdit(param).then(res => {
                        if (res.code == 200) {
                            this.$Message.success("操作成功");
                            this.updateModal = false;
                            this.getAllList();
                        } else {
                            this.$Message.warning(res.msg);
                        }
                        this.ModalLoading = false;
                    }).catch(error => {
                        console.log(error);
                        this.ModalLoading = false;
                    });
                }
                // 清空Table选择并恢复默认
                this.$refs.multipleTable.clearSelection();
            },
            remove(index, rows) {
                this.removeId = rows[index].id;
                this.deleteModal = true;
            },
            detele() {
                getEmpRewardDel(this.removeId)
                    .then(res => {
                        if (res.code == 200) {
                            this.$Message.success("操作成功");
                            this.getAllList();
                            this.deleteModal = false;
                        } else {
                            this.$Message.warning(res.msg);
                        }
                    })
                    .catch(error => {
                        console.log(error);
                    });
            },

            cancel(type) {
                if (type == 1) {
                    this.updateModal = false;
                } else if (type == 2) {
                    this.deleteModal = false;
                }
            },
            //改动
            selectValue() {
                let params = {
                    code: "reward_type"
                };
                const _this = this;
                getSelectValue(params)
                    .then(res => {
                        if (res.code == 200) {
                            this.itemList = res.data.childList;
                            let province_list = {};
                            for (let i = 0; i < this.itemList.length; i++) {
                                province_list[this.itemList[i].code] = this.itemList[i].name;
                            }
                            this.labelByValue = province_list;
                        }
                    })
                    .catch(error => {
                        console.log(error);
                    });
            },

            handleChange(file, fileList) {
                this.fileList = fileList.slice(-3);
            }
        },
    };
</script>

<style scoped lang="less">
    // @import "./../../assets/style/emp_common.less";
    @import "./../../assets/style/themeBase.less";

    .empReward {
        width: 100%;
        height: 100%;
        padding: 10px;
        box-sizing: border-box;
        background: #f5f5f5;

        .top {
            width: 100%;
            height: 72px;
            background: #fff;
            border-radius: 10px;
            display: flex;
            justify-content: space-between;
            align-items: center;

            .search {
                width: auto;
                margin-left: 20px;
                padding-top: 20px;
                display: flex;
                justify-content: flex-start;
                align-items: center;

                .list {
                    display: flex;
                    justify-content: flex-start;
                    align-items: center;
                    padding-bottom: 20px;
                    margin-right: 20px;

                    span {
                        width: 70px;
                    }
                }
            }

            .down {
                width: auto;
                margin-right: 20px;
            }
        }

        .bottom {
            width: 100%;
            padding: 20px;
            margin-top: 10px;
            box-sizing: border-box;
            height: calc(100% - 82px);
            background: #fff;
            border-radius: 10px;

            .down {
                width: 98%;
                margin: 0 auto;
                margin-top: 20px;
            }

            .msg {
                margin-bottom: 20px;
                display: flex;
                flex-wrap: wrap;

                .list {
                    display: flex;
                    justify-content: flex-start;
                    align-items: center;
                    margin-right: 24px;

                    p {
                        margin-right: 10px;
                        font-size: 16px;
                        color: #000;

                        &:nth-child(2) {
                            color: red;
                        }
                    }
                }
            }

            .updateCorp {
                cursor: pointer;
                margin-left: 5px;
                padding: 2px 4px;
                font-size: 12px;
                font-weight: 400;
                line-height: 1;
                color: #ffffff;
                border-radius: 3px;
                background-color: var(--themeColor);
            }
        }
    }

    .item {
        width: 400px;
        display: flex;
        margin: 0 auto;
        justify-content: space-between;
        align-items: center;
        margin-top: 10px;
        position: relative;
        margin-bottom: 20px;
        padding-left: 16px;
        box-sizing: border-box;

        .radio {
            width: 300px;
            display: flex;
            justify-content: center;
        }

        .tip {
            position: absolute;
            top: 8px;
            left: 0;
            color: red;
            font-size: 16px;
        }
    }

    // /deep/.ivu-icon-ios-close{
    //     color: #fff;
    //     &:hover{
    //         color: #fff;
    //     }
    // }



    /deep/.ivu-input-group {
        border-radius: 20px;
    }

    /deep/.ivu-input-group .ivu-input {
        border-radius: 20px 0 0 20px;
        border-color: #EBF2F8;
        background: #EBF2F8;
    }

    /deep/.ivu-input-group-append {
        border-radius: 0 20px 20px 0;
    }

    /deep/.el-tag.el-tag--success {
        background-color: #E7F8F2;
        border-color: #28D79C;
        color: #3FCF77;
    }

    /deep/.el-tag {
        border-radius: 2px;
    }

    /deep/.ivu-select-selection {
        border-radius: 2px;
    }

    /deep/.el-tag.el-tag--info {
        background-color: rgba(255, 72, 72, 0.1);
        border-radius: 2px;
        border-color: #FF4848;
        color: #FF4848;
    }

    .el-table {
        ::-webkit-scrollbar {
            height: 10px;
            /* 横向滚动条 高度 */
        }

        ::-webkit-scrollbar-thumb {
            // 滚动条上的滚动滑块
            // background: #000 !important;
            height: 10px;
        }
    }

    /deep/.ivu-modal-body {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-around;
    }
</style>

<style lang="scss" scoped>
    .EmpDiv {
        width: 100%;
        height: 50vh;
        display: flex;
        align-items: center;
        gap: 30px;

        .EmpLeft {
            width: calc(50% - 15px);
            height: 100%;
            overflow-y: auto;
        }

        .EmpRight {
            width: calc(50% - 15px);
            height: 100%;
            overflow-y: auto;
        }

    }
</style>
